package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallFormPurchaseManageMapper;
import org.linlinjava.litemall.db.dao.LitemallFormPurchaseMapper;
import org.linlinjava.litemall.db.domain.LitemallFormPurchaseManage;
import org.linlinjava.litemall.db.domain.LitemallShop;
import org.linlinjava.litemall.db.domain.LitemallShopAndOffer;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LitemallPurchaseManageService {

    @Resource
    private LitemallFormPurchaseManageMapper formPurchaseManageMapper;

    public void checkStatus(Integer id) {
        formPurchaseManageMapper.checkStatus(id);
    }

    public List<LitemallFormPurchaseManage> fetchPurchaseItem(Integer id,byte type){
        switch(type) {
            case 0 :
                return formPurchaseManageMapper.fetchNoQuotation(id);
            case 1 :
                return formPurchaseManageMapper.fetchHasQuotation(id);
            case 2 :
                return formPurchaseManageMapper.fetchWinBidding(id);
            case 3 :
                return formPurchaseManageMapper.fetchFinish(id);
        }
        return null;
    }

    public List<LitemallShopAndOffer> querySupplierDetails(Integer id, Boolean type,String contactTel){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        if(!StringUtils.isEmpty(contactTel)){
            contactTel="%"+contactTel+"%";
            map.put("contactTel",contactTel);
        }
        if (type){
            return formPurchaseManageMapper.queryNoQuotedPrices(map);
        }else {
            return formPurchaseManageMapper.queryQuotedPrices(map);
        }
    }

}
